function [X, indices, size_image] = PL_bayer_filter(x)
% [X, indices, size_image] = PL_bayer_filter(x)
% 
% PL_bayer_filter performs the Bayer filter on an RGB image of size [M N
% 3]. This filter is the forward operator for demosaicking. Its adjoint
% is PL_inverse_bayer_filter. To perform demosaicking see either  
% PL_demosaicking or PL_test_demosaicking.
%
% See also: PL_inverse_bayer_filter, PL_demosaicking, PL_test_demosaicking
%
% [1] M.J. Ehrhardt and S. Arridge, 
%     Vector-Valued Image Processing by Parallel Level Sets, 
%     IEEE Transactions on Image Processing (to appear), 2013
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------

    size_image = size(x);
    
    M = size_image(1);
    N = size_image(2);
        
    mask = 0 * x;
    
    mask(1:2:M, 2:2:N, 1) = 1;
    mask(1:2:M, 1:2:N, 2) = 1;
    mask(2:2:M, 2:2:N, 2) = 1;
    mask(2:2:M, 1:2:N, 3) = 1;
    
    indices = find(mask);
    
    X = x(indices);    
end